package com.aspyn.tp2;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.DatePicker.OnDateChangedListener;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TimePicker;
import android.widget.Toast;

public class ToastProj2Activity extends Activity implements OnClickListener, OnItemSelectedListener {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button btnToast = (Button)findViewById(R.id.btnToast);
        btnToast.setText("Toast It!");
        btnToast.setOnClickListener(this);
        
        Spinner spin = (Spinner)findViewById(R.id.spnCourse);
        ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.courseArray, android.R.layout.simple_spinner_item);
        spin.setAdapter(adapter);
        spin.setOnItemSelectedListener(this);
        
        DatePicker dp = (DatePicker)findViewById(R.id.datePicker);
        dp.updateDate(2011, 0, 1);
      

    }

	public void onClick(View v) {
		// TODO Auto-generated method stub
		Spinner spnCourse = (Spinner)findViewById(R.id.spnCourse);
		EditText txtName = (EditText)findViewById(R.id.txtName);
		EditText txtHometown = (EditText)findViewById(R.id.txtHometown);
		DatePicker dp = (DatePicker)findViewById(R.id.datePicker);
		TimePicker tp = (TimePicker)findViewById(R.id.timePicker);
		
		int day = dp.getDayOfMonth(), month = dp.getMonth()+1, year = dp.getYear();
		int hour = tp.getCurrentHour(), minute = tp.getCurrentMinute();
		
		String name = txtName.getText().toString(), hometown = txtHometown.getText().toString(), 
				course = spnCourse.getSelectedItem().toString(), bd = Integer.toString(month) + "/" + Integer.toString(day) + "/" + Integer.toString(year);
		
		String toastStr = name + "; " + bd + "; " + course +"; " + hometown;
		
		Toast.makeText(this, toastStr, Toast.LENGTH_LONG).show();
	}

	public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
			long arg3) {
		Toast.makeText(this, "State changed", Toast.LENGTH_SHORT).show();
		// TODO Auto-generated method stub
		
	}

	public void onNothingSelected(AdapterView<?> arg0) {
		// TODO Auto-generated method stub
		
	}
}